package com.idroc.message.impl;

import org.apache.mina.common.ByteBuffer;

import com.idroc.message.AbstractMessage;
import com.idroc.message.MessageType;

/**
 * 空操作消息
 * @author 詹都林(zhandl@tianya.cn) <br>
 * @date May 16, 2009 8:18:59 AM <br>
 * @version 1.0.0
 * @descript: 类功能简称<br>测试 消息承载数据正确性
 *            <p>
 *            备注:<br>
 *            </p>
 */
public class NoopMessage extends AbstractMessage {
	
	private ByteBuffer data = null;
	
	public NoopMessage() {
		super();
		this.data = ByteBuffer.allocate(512).setAutoExpand(true);
	} 

	@Override
	protected void decodeMessage(ByteBuffer inBuffer) {
		
		data.put(inBuffer);
		data.flip();
	}

	@Override
	protected void encodeMessage(ByteBuffer outBuffer) {

		data.flip();
		outBuffer.put(data);
	} 
	
	public void write(String info) {
		
		data.put(info.getBytes());
	}
	
	@Override
	public String toString() {
		
		int length = data.limit();
		byte[] info = new byte[length];
		data.position(0);
		data.get(info);
		data.position(length);
		return new String(info);
	} 
}
